<div class="cart_product">
<form action="/update_product.php" method="post" name="myform" >
<?
if(!$none){
   $number = 0;
   $j = 0;
   ?>
   <span class="list_top">Giỏ hàng</span>
   <table class="show_product" style="line-height: 225%; width: 100%;" border='1'>
    <tr class="list_item">
      <td>TT</td>
      <td>Mã mặt hàng</td>
      <td>Tên mặt hàng</td>
      <td>Giá bán (VNĐ)</td>
      <td>Số lượng</td>
      <td>Tổng cộng</td>
      <td>Delete</td>
   </tr>
   <?
   $total_cart = 0;
   $j          = 0;
   for($i = 0; $i < $total; $i++){
   $j++;
   $db_product = new db_query("SELECT pro_id,pro_name, pro_price
                               FROM products_multi
                               WHERE pro_id = '".$_SESSION['Cart'][$i]['id']."'");
   $row = mysql_fetch_assoc($db_product->result);
   ?>   
   <tr>
      <td class="list_number"><?=$j?></td>
      <td><?=$_SESSION['Cart'][$i]['id']?></td>
      <td><?=$row['pro_name']?></td>
      <td><?=number_format($row['pro_price'])?></td>
      <td>
        <input type="hidden" name="product_id" value="<?php echo $_SESSION["Cart"][$i]["id"];?>" />
	     <input name="total_product_<?=$i?>" class="total_product" value="<?php echo $_SESSION["Cart"][$i]["total_pro"];?>" size="1" />
      <td class="total_price"><?=number_format($row["pro_price"]*$_SESSION["Cart"][$i]["total_pro"]); ?></td>
      
      <td class="delete"><a href="delete_product.php?id=<?php echo $_SESSION["Cart"][$i]["id"];?>">Xóa</a></td>
   </tr>
   
   <?
   $total_cart += $row['pro_price'] * $_SESSION['Cart'][$i]['total_pro'];
   }
   ?>
   <tr class="list_total">
      <td colspan="5">Tổng giá trị đơn hàng của bạn</td>
      <td colspan="2" id="total_cart"><?=number_format($total_cart)?></td>
   </tr>
   </table>
   <div class="select_all_method">
      </button><a href="/delete_all_product.php" class="select_method">Xóa giỏ hàng</a>
      <a href="myform.submit()"><a href="/" class="select_method">Tiếp tục mua hàng</a></a>
      <a href="myform.submit()"><a href="/payment.php" class="select_method">Đặt hàng</a></a>
   </div>
   </form>
   <?   
}
else{
   echo "Giỏ hàng của bạn đang rỗng !";
}
//remove_allitem();
?>
</div>
<script>
$(document).ready(function(){
   $('.total_product').keyup(function(){
      var i=0;
      var pro_id = $(this).parent().prev().prev().prev().text();
      var quantity   = $(this).val();
      var price      = $(this).parent().prev().html();
      if(quantity) {quantity = parseInt(quantity)}
      else {quantity =0}
      price = price.replace(/,/g,"");
      price = parseFloat(price);
      var total   = addCommas(quantity*price+"");
      total = total.replace(/\./g,',');
      $(this).parent().next().html(total);
      var sum_cart1 = addCommas(sum_cart()+"").replace(/\./g,',');
      $('#total_cart').html(sum_cart1);
      $.ajax({
         url:"/update_product.php",
         type:"POST",
         data:{product_id:pro_id,total_product:quantity}      
      }).done(function(reponse){
         
      });
   })
   function sum_cart(){
      var total_cart = 0;
      $('.total_price').each(function(){
         val   = $(this).html();
         val = val.replace(/,/g,"");
         val = parseFloat(val);
         total_cart  += val;
      });
      return total_cart;
   }
})
   
</script>